package com.tgb.lk.demo.model;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.Serializable;
import java.util.ArrayList;


import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.R.integer;
import android.util.Xml;

import com.tgb.lk.ahibernate.annotation.Column;
import com.tgb.lk.ahibernate.annotation.Id;
import com.tgb.lk.ahibernate.annotation.Table;
import com.tgb.lk.demo.annotation.PrimaryKey;

//�˴�û�м�Table����,����������Ļ���,��������@Columnע����ֶ���������ͬ��ᱻ����������.
@Table(name = "JokeBean")
public class JokeBean implements Serializable{
	@Id
	@Column(name = "id")
	private int id; // ���,int����,��ݿ⽨��ʱ���ֶλ���Ϊ����
	
	@PrimaryKey
	@Column(name = "joke_id", type = "INTEGER")
	private int joke_id=-1; // ����һ������ֵ,��type = "INTEGER"�淶һ�°�.
	
	@Column(name = "joke_type", type = "INTEGER")
	private int joke_type=-1; // ����һ������ֵ,��type = "INTEGER"�淶һ�°�.
	
	@Column(name = "joke_isRead", type = "INTEGER")
	private int joke_isRead=-1; // ����һ������ֵ,��type = "INTEGER"�淶һ�°�.
	
	@Column(name = "joke_title", length = 20)
	private String joke_title; // ���ֳ���һ�㲻�ᳬ��20���ַ��,length=20����ֶεĳ�����20
	
	@PrimaryKey
	@Column(name = "joke_text", length = 2000)
	private String joke_text; // ���ֳ���һ�㲻�ᳬ��20���ַ��,length=20����ֶεĳ�����20
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getJoke_id() {
		return joke_id;
	}

	public void setJoke_id(int joke_id) {
		this.joke_id = joke_id;
	}


	public static ArrayList<JokeBean> parse(InputStream inputStream,int k) {
		ArrayList<JokeBean> list = new ArrayList<JokeBean>();
		int i=0;
		JokeBean bean = null;
        //���XmlPullParser������
        XmlPullParser xmlParser = Xml.newPullParser();
        try {        	
            xmlParser.setInput(inputStream, "utf-8");
            //��ý�����¼���������п�ʼ�ĵ��������ĵ�����ʼ��ǩ�������ǩ���ı��ȵ��¼���
            int evtType=xmlParser.getEventType();
			//һֱѭ����ֱ���ĵ�����    
			while(evtType!=XmlPullParser.END_DOCUMENT){ 
	    		String tag = xmlParser.getName(); 
			    switch(evtType){ 
			    	case XmlPullParser.START_TAG:
			    		if(tag.equalsIgnoreCase("title")) 
			    		{
			    			i++;
			    			bean = new JokeBean();
			    			bean.setJoke_id(i);
			    			bean.setJoke_type(k);
			    			bean.setJoke_isRead(0);
			    			bean.setJoke_title(xmlParser.getAttributeValue(null, "name"));
			    			try {
								bean.setJoke_text(xmlParser.nextText());
							} catch (IOException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
			    		}
			    		
			    		break;
			    	case XmlPullParser.END_TAG:	
					   	//������ǩ������Ѷ�����ӽ����
				       	if (tag.equalsIgnoreCase("title") && bean != null) { 
				       		list.add(bean);
				       		bean = null; 
				       	}
				       	break; 
			    }
			    int a;
				try {
					a = xmlParser.next();
					 evtType=a;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			   
			}		
        } catch (XmlPullParserException e) {
        	e.printStackTrace();
        } finally {
        	try {
				inputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}	
        }      
        return list;       
	}

	public int getJoke_type() {
		return joke_type;
	}

	public void setJoke_type(int joke_type) {
		this.joke_type = joke_type;
	}

	public String getJoke_title() {
		return joke_title;
	}

	public void setJoke_title(String joke_title) {
		this.joke_title = joke_title;
	}

	public String getJoke_text() {
		return joke_text;
	}

	public void setJoke_text(String joke_text) {
		this.joke_text = joke_text;
	}

	public int getJoke_isRead() {
		return joke_isRead;
	}

	public void setJoke_isRead(int joke_isRead) {
		this.joke_isRead = joke_isRead;
	}	
}
